package com.ngc.mall.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ngc.mall.domain.SpuDomain;
import com.ngc.mall.domain.ThemeDomain;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 *  theme Mapper
 *
 * @author : Chen Xiao Lin
 * @Date : 2023/5/15 9:52
 **/

@Mapper
public interface ThemeMapper extends BaseMapper<ThemeDomain> {

    @Select("select * from spu where id in (select spu_id from spu_theme where theme_id = #{themeId})")
    List<SpuDomain> findThemeWithSpus(Long themeId);

    @Insert({
            "<script>",
            "insert into spu_theme(spu_id,theme_id) values",
            "<foreach collection='themeIdList' item='item'  separator=',' >",
            "(#{spuId},#{item})",
            "</foreach>",
            "</script>"
    })
    Boolean insertBatchSpuTheme(@Param("spuId") Long spuId,@Param("themeIdList") List<Long> themeIdList);

    @Select("select id from theme where id in (select theme_id from spu_theme where spu_id=#{spuId})")
    List<Long> findIdBySpus(Long spuId);

    @Delete("delete from spu_theme where theme_id = #{id}")
    Boolean removeSpuIdById(Long id);
}
